import request from "@/utils/request"
import { headImg } from "@/utils/utils"
import { SHARE_TYPE, GOODS_STRATEGY_TYPE } from "@/config/types"

/**
 * 用户分享图
 */
export function userShareImg(data) {
  return request.post(`/wx-images/user-share-img`, data)
}

/**
 * 商品分享图
 */
export function goodsShareImg(goods:any) {
  const type = goods.saleStrategy === GOODS_STRATEGY_TYPE.NORMAL ? goods.type : goods.saleStrategy
  const config = {
    REAL: SHARE_TYPE.REAL_GOODS,
    PINK: SHARE_TYPE.PINK_GOODS,
    SCORE: SHARE_TYPE.SCORE_GOODS,
    VIRTUAL: SHARE_TYPE.VIRTUAL_GOODS,
    SECKILL: SHARE_TYPE.SECKILL_GOODS
  }
  return request.post(`/products/create-share-img`, {
    title: goods.name,
    price: goods.salePrice,
    keyType: config[type],
    shareImg: goods.shareImg,
    firstImg: headImg(goods.images),
    productId: goods.id,
  })
}


/**
 * 获取分享参数
 */
export function shareInfoById(id) {
  return request.get(`/user-shares/get-by-id/${id}`)
}


/**
 * 获取分享 code
 */
export function getShareCode(path) {
  return request.get(`/user-shares/get-share-code?pagePath=${path}`)
}


/**
 * 获取商品分享 code
 */
export function getProductShareCode(params) {
  // @ts-ignore
  return request.get('/user-shares/get-product-share-code', { params }, { isAuth: false })
}